<?php

	$fileURL = $_GET['fileurl'];
	$fileName = basename($fileURL);
	$file_extension = strtolower(substr(strrchr($fileURL,"."),1));

	if ((isset($fileURL))&&(file_exists($fileURL))) {
		switch( $file_extension ) {
			case "doc":		$ctype="application/msword"; break;
			case "docx":	$ctype="application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
			case "pdf":		$ctype="application/pdf"; break;
			case "txt":		$ctype="text/plain"; break;
			case "xlsx":	$ctype="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
			case "xls":		$ctype="application/vnd.ms-excel"; break;
			case "zip": 	$ctype="application/zip, application/x-compressed-zip"; break;
		}
	}
	
	header("Pragma: public"); // required
	header("Expires: 0");
	header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
	header("Cache-Control: private",false); // required for certain browsers
	header("Content-type: application/force-download");
	header('Content-Disposition: inline; filename="' . $fileName . '"');
	header("Content-Transfer-Encoding: Binary");
	header("Content-length: ".filesize($fileURL));
	
	header("Content-Type: $ctype");
	header('Content-Disposition: attachment; filename="' . $fileName . '"');
	
	readfile("$fileURL");

?>